package test1230am;

public class Test21 {
    public static void main(String[] args) {

        // (22)打印两个数组的交集
        int[] arr = {1,2,3,4,5};
        int[] brr = {3,4,5,6,7};
        aandb(arr, brr);
    }
    public static void aandb(int[] arr, int[] brr) {
        int[] mid = new int[arr.length];
        int index = 0;
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < brr.length; j++) {
                if(arr[i] == brr[j]) {
                    mid[index++] = arr[i];
                }
            }
        }
        int[] result = new int[index];
        for(int i = 0; i < index; i++) {
            result[i] = mid[i];
        }
        for(int i = 0; i < result.length; i++) {
            System.out.print(result[i] + " ");
        }
    }
}
